package health_system.health_system.dto;

import health_system.health_system.entity.Moment;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;
import java.util.List;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class MomentWithMediaStatsDTO {
    private Long id;
    private Long userId;
    private String username;
    private String userAvatarUrl;
    private String content;
    private Long mediaCount;
    private Long imageCount;
    private Long videoCount;
    private Moment.VisibilityType visibility;
    private List<MomentMediaDTO> mediaList;
    private LocalDateTime createdAt;
    private LocalDateTime updatedAt;
    
    public static MomentWithMediaStatsDTO fromMomentAndStats(
            Moment moment, 
            Long mediaCount,
            Long imageCount,
            Long videoCount) {
        
        if (moment == null) {
            return null;
        }
        
        MomentWithMediaStatsDTO dto = new MomentWithMediaStatsDTO();
        dto.setId(moment.getId());
        
        if (moment.getUser() != null) {
            dto.setUserId(moment.getUser().getId());
            dto.setUsername(moment.getUser().getUsername());
            dto.setUserAvatarUrl(moment.getUser().getAvatarUrl());
        }
        
        dto.setContent(moment.getContent());
        dto.setMediaCount(mediaCount);
        dto.setImageCount(imageCount);
        dto.setVideoCount(videoCount);
        dto.setVisibility(moment.getVisibility());
        dto.setCreatedAt(moment.getCreatedAt());
        dto.setUpdatedAt(moment.getUpdatedAt());
        
        return dto;
    }
} 